const install = (Vue, vm) => {
	const isLogin = () => {
		const token = vm.vuex_token
		console.log(token)
		if (!token) {
			// console.log(getCurrentPages().pop().route)
			const currentPage=getCurrentPages().pop()
			const {options,route}=currentPage
			const optionKeys=Object.keys(options)
			let params=''
			if(optionKeys.length!==0){
				params=optionKeys.reduce((pre,current)=>{
					return pre+current+'='+options[current]+'&'
				},'?').slice(0,-1)
			}
			uni.setStorageSync('back_url',route+params)
			setTimeout(() => {
				vm.$u.route({
					url: 'pages/auth/login',
					type: 'redirectTo'
				})
			}, 2000)
			return false
		}
		return true
	}
	//更新用户信息
	const updataUser=async()=>{
		//请求用户信息
		const userInfo=await vm.$u.api.userInfo()
		//缓存用户信息
		vm.$u.vuex('vuex_user',userInfo)
	}
	vm.$u.utils = {
		isLogin,
		updataUser
	};
}


export default {
	install
}
